package com.ybkj.daijia.api.checker;

import com.ybkj.daijia.serverUtils.ExcelUtil;
import java.io.IOException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author zhyu
 * @date 2019-08-07 14:24:57
 */
@Controller
@RequestMapping("checker")
public class CheckerController {

    @Autowired
    private CheckDriverService checkDriverService;

    @RequestMapping(path = "driverRebateMoneyCheck", method = RequestMethod.HEAD)
    public ModelAndView driverRebateMoneyCheck(@RequestParam("token") String token) {
        if (token.equals("super")) {
            List<List<String>> data = checkDriverService.checkDriverRabateMoney();
            String path = "/opt/tomcat/logs/record";
            try {
                ExcelUtil.export(path, data);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        ModelAndView mv = new ModelAndView();
        mv.setViewName("login");
        return mv;
    }

    @RequestMapping(path = "changeDriverRabteInDriverPaymentToDriverRebatePayment", method = RequestMethod.HEAD)
    public ModelAndView changeDriverRabteInDriverPaymentToDriverRebatePayment(
        @RequestParam("token") String token) {
        if (token.equals("super")) {
            List<List<String>> data = checkDriverService
                .changeDriverRabteInDriverPaymentToDriverRebatePayment();
            String path = "/opt/tomcat/logs/record";
            try {
                ExcelUtil.export(path, data);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        ModelAndView mv = new ModelAndView();
        mv.setViewName("login");
        return mv;
    }

}
